﻿using ErrorOr;
using Gnivc.CarDealership.Api.Domain.Enums;
using Gnivc.CarDealership.Api.Domain.Extensions;
using Gnivc.CarDealership.Api.Domain.Primitives;

namespace Gnivc.CarDealership.Api.Domain.ValueObjects;

public class Engine : ValueObject
{
    public double Volume { get; init; }
    public int Power { get; init; }
    public EngineType Type { get; set; }

    private Engine() { }

    private Engine(double volume, int power, EngineType type)
    {
        Volume = volume;
        Power = power;
        Type = type;
    }

    public static ErrorOr<Engine> Create(double volume, int power, EngineType type)
    {
        if (volume < 0)
            return Error.Validation();

        if (power < 0)
            return Error.Validation();

        return new Engine(volume, power, type); 
    }

    protected override IEnumerable<object> GetEqualityComponents()
    {
        yield return Volume;
        yield return Power;
        yield return Type;
    }

    public override string ToString()
    {
        return $"{Volume} л. / {Power} л.с. / {Type.ToAttributeString()}";
    }
}